<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/2/23 0023
 * Time: 21:27
 */
namespace app\home\controller;
class common
{
  public function __construct()
  {
      //1.获取配置文件中的数据
       $this->getWebsite();
      //2.获取分类数据
      $this->getCategory();
      //3.获取右侧分类数目
      $this->getCategoryList();
      //4.获取标签云
      $this->getTags();
      //5.友链
      $this->getLink();
      //6.最新文章
      $this->getArticle();
  }
  // 6.获取最新文章
     public function  getArticle(){
         $articlesData=Db::table('article')->orderBy('sendtime','DESC')->limit(2)->get(['aid','sendtime','title']);
       View::with('articlesData',$articlesData);
     }
  //  5.获取友链
     public function getLink(){
      $linkData=Db::table('link')->get();
      //分配变量
      View::with('linkData',$linkData);
    }
  //4.获取标签云
    public function getTags(){
       $tags= Db::table('tag')->get();
       View::with('tags',$tags);
    }
  //3.获取分类数目
    public function getCategoryList(){
      $categoryListData=Db::table('category')->get();
      foreach ($categoryListData as $k=>$v){
          $categoryListData[$k]['total']=Db::table('article')->where('category_cid',$v['cid'])->count();
      }
      View::with('categoryListData',$categoryListData);
    }
  //2.获取分类数据
    public function  getCategory(){
        $cateData=Db::table('category')->where('pid',0)->get();
        //分配到页面
        View::with('cateData',$cateData);
//        p($cateData);die;
    }
    //1.获取站点配置
    public function  getWebsite(){
         $websiteData=Db::table('website')->lists('name,value');
         //分配到页面
         View::with('websiteData',$websiteData);
    }
}
